package com.example.cardgame

import android.content.Intent
import android.content.SharedPreferences
import android.graphics.Bitmap
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.enableEdgeToEdge
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity1 : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main1)

        // 获取SharedPreferences
        val sharedPreferences = getSharedPreferences("user_info", MODE_PRIVATE)

        //最高分
        val highScore = intent.getIntExtra("HIGH_SCORE", 0)
        val highScoreTextView = findViewById<TextView>(R.id.textView19)
        highScoreTextView.text = highScore.toString()

        // 从SharedPreferences中读取用户信息
        val data1 = sharedPreferences.getString("inputText1", "") ?: ""
        val data2 = sharedPreferences.getString("inputText2", "") ?: ""
        val data3 = sharedPreferences.getString("inputText3", "") ?: ""
        val data4 = sharedPreferences.getString("inputText4", "") ?: ""
        val data5 = sharedPreferences.getString("selected_option", "") ?: ""
        val selectedCheckboxes = sharedPreferences.getStringSet("selected_checkboxes", setOf()) ?: setOf()
        val data6 = selectedCheckboxes.joinToString(", ")
        val data7 = "$data1 $data2"

        // 设置TextView的内容
        findViewById<TextView>(R.id.textView3).text = data1
        findViewById<TextView>(R.id.textView11).text = data2
        findViewById<TextView>(R.id.textView13).text = data3
        findViewById<TextView>(R.id.textView15).text = data4
        findViewById<TextView>(R.id.textView9).text = data5
        findViewById<TextView>(R.id.textView17).text = data6
        findViewById<TextView>(R.id.textView).text = data7

        val imageView = findViewById<ImageView>(R.id.imageView)
        imageView.setImageResource(R.drawable.img)

        // 点击按钮去编辑基础信息
        val button1 = findViewById<Button>(R.id.button)
        button1.setOnClickListener {
            startActivity(Intent(this, MainActivity2::class.java))
        }

        // 点击按钮去玩游戏
        val button2 = findViewById<Button>(R.id.button2)
        button2.setOnClickListener {
            startActivity(Intent(this, MainActivity::class.java))
        }

    }
}